import { defineStore } from 'pinia'
import { ref } from 'vue'
import { userGetInfoService } from '../../api/user/user'
export const useUserStore = defineStore(
  'big-user',
  () => {
    const token = ref('')
    const setToken = (newToken) => {
      token.value = newToken
    }
    const removeToken = () => {
      token.value = ''
    }
    //获取用户信息
    const user = ref({})
    const getUserInfo = async () => {
      const { data: res } = await userGetInfoService()
      user.value = res.data
    }
    //删除用户信息
    const setUserInfo = (obj) => {
      user.value = obj
    }
    return {
      token,
      user,
      setUserInfo,
      getUserInfo,
      setToken,
      removeToken
    }
  },
  {
    persist: true
  }
)
